package com.china_goldcard.myselectview;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * MyDefaultDataAdapter
 */
public class MyDefaultDataAdapter implements MySelectDataAdapter{

    public MyDefaultDataAdapter(Context context){
        this.context = context;
    }

    private Context context;

    @Override
    public MySelectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context).inflate(R.layout.my_select_item,parent,false);
        return new MyDefaultSelectViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MySelectViewHolder holder, int position, MySelectItemModel model) {
        MyDefaultSelectViewHolder viewHolder = (MyDefaultSelectViewHolder)holder;
        if (model.isSelected()){
            viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(context,R.color.select_view_selected_color));
            viewHolder.dotV.setBackgroundResource(R.drawable.selected_dot);
        }else{
            viewHolder.dotV.setBackgroundResource(R.drawable.unselected_dot);
            viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(context,R.color.select_view_unselected_color));
        }
        viewHolder.textView.setText(model.getTitle());
    }
}
